#include "commond.hpp"

int main()
{
    CreateNamedPipe(PIPE_NAME);

    std::cout << "read begin" << std::endl;
    int rfd = open(PIPE_NAME, O_RDONLY);
    assert(rfd > 0);
    std::cout << "read end" << std::endl; 
    char buffer[1024];
    while(true)
    {
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if(n > 0)  
        {
            buffer[n - 1] = 0;
            puts(buffer);
        }
        else if(n == 0)
        {
            std::cout << "client quit, me to" << std::endl;
            break;
        }
        else
        {
            std::cout << "eorror:" << strerror(errno) << std::endl;
            break;
        }
    }

    close(rfd);
    sleep(5);
    RemovePipe(PIPE_NAME);
    return 0;
}